package com.julian.warehouse.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.julian.warehouse.R;
import com.julian.warehouse.bean.GoodsBean;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/8/9.
 */

public class LvAdapter extends BaseAdapter {
    private Context mContext;
    private List<GoodsBean> dataList;

    public LvAdapter(Context mContext, List<GoodsBean> dataList){
        this.mContext = mContext;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_lv_kucun,null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        final GoodsBean goodsBean = dataList.get(position);
        holder.tv_gname.setText(goodsBean.getGname());
        holder.tv_kucun.setText("库存："+goodsBean.getCount()+"");
        holder.tv_price.setText("售价："+goodsBean.getPrice()+"");


        return convertView;
    }


    class ViewHolder{
        private final TextView tv_gname;
        private final TextView tv_kucun;
        private final TextView tv_price;
        private ImageView iv_goods;


        public ViewHolder(View v){

            iv_goods = v.findViewById(R.id.iv_goods);
            tv_gname = v.findViewById(R.id.tv_gname);
            tv_kucun = v.findViewById(R.id.tv_kucun);
            tv_price = v.findViewById(R.id.tv_price);
        }


    }
}
